package grape.attend.service.group.impl;

import grape.attend.service.group.api.IGroupUserRelService;
import grape.attend.service.group.po.Group;
import grape.attend.service.group.mapper.GroupMapper;
import grape.attend.service.group.api.IGroupService;
import grape.attend.service.group.po.GroupUserRel;
import grape.common.service.common.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  考勤组设置表 服务实现类
 * </p>
 *
 * @author yangwei
 * @since 2020-05-08
 */
@Service
public class GroupServiceImpl extends BaseServiceImpl<GroupMapper, Group> implements IGroupService {

    @Autowired
    private IGroupUserRelService iGroupUserRelService;

    @Override
    public List<Group> getGroupByUserId(String userId) {
        assertParamNotEmpty(userId,"用户id不能为空");
        List<GroupUserRel> groupUserRels = iGroupUserRelService.getByUserId(userId);
        if (!isEmpty(groupUserRels)) {
            Collection<Group> groups = listByIds(groupUserRels.stream().map(rel -> rel.getGroupId()).collect(Collectors.toList()));

            return (List<Group>) groups;
        }
        return null;
    }
}
